package com.hsy.bibc.modules.login;

import android.content.Intent;

import com.deparse.dpframe.ui.activity.DPSplashActivity;
import com.deparse.dpframe.utils.DPCommonUtil;
import com.deparse.dpframe.utils.DPLogUtil;
import com.hsy.bibc.modules.login.LoginActivity;
import com.hsy.bibc.R;
import com.hsy.bibc.modules.main.MainActivity;
import com.hsy.bibc.modules.msg.activity.ActivityMsgDetail;
import com.hsy.bibc.utils.CommonUtils;
import com.tencent.android.tpush.XGPushClickedResult;
import com.tencent.android.tpush.XGPushManager;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by hsy on 2016/3/24.
 */
public class SplashActivity extends DPSplashActivity {
    @Override
    protected int getSplashContentView() {
        DPLogUtil.d("getSplashContentView");
        return R.layout.activity_splash;
    }

    @Override
    protected void doInit() {
//        Application.getInstance().getContacts(null);
    }

    @Override
    protected long getDuration() {
        return 3000;
    }

    @Override
    protected void doJump() {

        if (CommonUtils.checkLogin(getApplicationContext())) {
            startActivity(MainActivity.class);
        } else {
            startActivity(LoginActivity.class);
        }
        finish();
    }

    @Override
    protected void onStart() {
        super.onStart();
        XGPushClickedResult click = XGPushManager.onActivityStarted(this);
        if (click != null) {
            String customContent = click.getCustomContent();
            DPLogUtil.d("customContent=" + customContent);
            if (customContent != null && customContent.length() != 0) {

                try {
                    JSONObject result = new JSONObject(customContent);
                    String id = result.optString("id");
                    Intent intent = new Intent(this, ActivityMsgDetail.class);
                    intent.putExtra("fromNotification", true);
                    intent.putExtra("id", id);
                    startActivity(intent);
                    finish();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    @Override
    protected void onStop() {
        XGPushManager.onActivityStoped(this);
        super.onStop();
    }
}
